# Contributor: Dermot Bradley <dermot_bradley@yahoo.com>
# Maintainer: Dermot Bradley <dermot_bradley@yahoo.com>
pkgname=hd-idle
pkgver=1.21
pkgrel=0
pkgdesc="spin down idle hard disks"
url="https://github.com/adelolmo/hd-idle"
arch="all"
license="GPL-3.0-only"
makedepends="
	go
	"
subpackages="
	$pkgname-doc
	$pkgname-logrotate
	$pkgname-openrc
	"
options="!check" # There are no testcases
source="$pkgname-$pkgver.tar.gz::https://github.com/adelolmo/hd-idle/archive/v$pkgver.tar.gz
	hd-idle.confd
	hd-idle.initd
	hd-idle.logrotate
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -o hd-idle hdidle.go main.go
}

package() {
	install -D -m755 hd-idle "$pkgdir"/usr/sbin/hd-idle

	install -m 644 -D "$srcdir"/hd-idle.confd "$pkgdir"/etc/conf.d/hd-idle
	install -m 755 -D "$srcdir"/hd-idle.initd "$pkgdir"/etc/init.d/hd-idle
	install -m 644 -D "$srcdir"/hd-idle.logrotate "$pkgdir"/etc/logrotate.d/hd-idle

	mkdir -p "$pkgdir"/usr/share/man/man8
	install -m644 \
		debian/hd-idle.8 \
		"$pkgdir"/usr/share/man/man8/
}

logrotate() {
	pkgdesc="spin down idle hard disks (logrotate configuration)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel logrotate"

	amove etc/logrotate.d/hd-idle
}

sha512sums="
9afe5affd3244ad546a17b840f2c499a3597e5af08b6f514edae3407b99c2ab7e8dc9bd51999e229ba48dd8df97024fa70380b996d749adc3fee2024542a8018  hd-idle-1.21.tar.gz
6a159e6fb0517a560e98a1389b105609d7d6c10c22ac905520a5f5d47da1a6f01ab6cc90a95f61b17f405bae2bd230ff5256502ac697ed5ff0107e2d4a7517b8  hd-idle.confd
3b3319636b463af92748a4967e44311f8caebe2c869ba5289bb11bec2cdbad5e798a5a75a9bb81b14727404e9328e9444f298748348864171322c07d8f72608a  hd-idle.initd
ec89ea63060c4684d892eae45ea686617620a966c873e863e9e7449418bc4d8c28e3175b050e89857c6ac4a969e71cebc99bba792e1e0c0af787fb246b0d9629  hd-idle.logrotate
"
